package com.hxd.otc.module.convenience.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.common.enums.ConvenienceModuleStatusEnum;
import com.hxd.otc.module.convenience.bean.RefuelingServiceBean;
import com.hxd.otc.utils.GlideUtils;
import com.hxd.otc.utils.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/12/14 0014.
 * description ${便民服务Adapter}
 */
public class ConvenienceAdapter extends BaseAdapter<ConvenienceAdapter.ConvenienceHolder, RefuelingServiceBean> {


    public ConvenienceAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull ConvenienceHolder holder, int position) {
        RefuelingServiceBean item = getItem(position);
        holder.tvDesc.setText(item.getModuleName());
        GlideUtils.setImage(mContext, UIUtils.getServiceImageUrlByPath(item.getModuleIcon()), R.mipmap.icon_convenience_default,
                R.mipmap.icon_convenience_default, holder.ivIcon);
        holder.tvToBeOpened.setVisibility(item.getStatusEnum() == ConvenienceModuleStatusEnum.OPENED ? View.GONE : View.VISIBLE);
        holder.tvToBeOpened.setText(item.getStatusEnum().getDesc());
    }

    @NonNull
    @Override
    public ConvenienceHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ConvenienceHolder(mInflater.inflate(R.layout.item_convenience, parent, false));
    }

    static class ConvenienceHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_icon)
        ImageView ivIcon;
        @BindView(R.id.tv_desc)
        TextView tvDesc;
        @BindView(R.id.tv_to_be_opened)
        TextView tvToBeOpened;

        ConvenienceHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
